using System.Collections;
using System.Collections.Generic;
using MoonSharp.Interpreter;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;

namespace GGameFramework.Test.Input
{
    [CreateAssetMenu(fileName = "GameInput", menuName = "GGameFramework/PlayerInput")]
    public class PlayerInput : ScriptableObject,InputActionsConfig.IKeyboardActions,InputActionsConfig.IGamepadActions
    {
        private InputActionsConfig _config;
        
        public event UnityAction<Vector2> onMove = delegate {};
        public event UnityAction onStopMove = delegate {};
        public event UnityAction onFall = delegate {};
        // void OnEnable()
        // {
        //    
        //
        //     _config.Keyboard.SetCallbacks(this);
        //     _config.Gamepad.SetCallbacks(this);
        // }
        //
        // public void EnablePlayerInput()
        // {
        //     _config.Disable();
        //     _config.Gamepad.Enable();
        // }

        public void SwitchToDynamicUpdateMode() => InputSystem.settings.updateMode = InputSettings.UpdateMode.ProcessEventsInDynamicUpdate;

        public void SwitchToFixedUpdateMode() => InputSystem.settings.updateMode = InputSettings.UpdateMode.ProcessEventsInFixedUpdate;

        public void DisableAllInputs() => _config.Disable();
        
       
        
        public void OnMove(InputAction.CallbackContext context)
        {
            if (context.performed)
            {
                // Debug.Log("开始移动");
                onMove.Invoke(context.ReadValue<Vector2>());
            }

            if (context.canceled)
            {
                // Debug.Log("停止移动");
                onStopMove.Invoke();
                //onStopMove.Invoke();
            }
        }

        public void OnJump(InputAction.CallbackContext context)
        {
            Debug.Log("OnJump");
        }

        public void OnFall(InputAction.CallbackContext context)
        {
            Debug.Log("OnFall");
        }

        public void OnAttack(InputAction.CallbackContext context)
        {
            Debug.Log("OnAttack");
        }

        public void OnDash(InputAction.CallbackContext context)
        {
            Debug.Log("OnDash");
        }
    }
}

